/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.cax.controller;

import java.util.List;

import com.comac.ins.cax.domain.bo.CaxGeometricCheckBo;
import com.comac.ins.cax.domain.vo.CaxQualityCheckerVo;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.comac.ins.cax.domain.vo.CaxGeometricCheckVo;
import com.comac.ins.cax.service.ICaxGeometricCheckService;


/**
 * 【cax几何校验】
 *
 * @author Lion Li
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cax/geometricCheck")
public class CaxGeometricCheckController extends BaseController {

    private final ICaxGeometricCheckService caxGeometricCheckService;

    /**
     * 查询【cax几何校验】列表
     */
    @SaCheckPermission("cax:geometricCheck:list")
    @GetMapping("/list")
    public TableDataInfo<CaxGeometricCheckVo> list(CaxGeometricCheckBo bo, PageQuery pageQuery) {
        return caxGeometricCheckService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出【cax几何校验】列表
     */
    @SaCheckPermission("cax:geometricCheck:export")
    @Log(title = "【cax几何校验】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CaxGeometricCheckBo bo, HttpServletResponse response) {
        List<CaxGeometricCheckVo> list = caxGeometricCheckService.queryList(bo);
        ExcelUtil.exportExcel(list, "【cax几何校验】", CaxGeometricCheckVo.class, response);
    }

    /**
     * 获取【cax几何校验】详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("cax:geometricCheck:query")
    @GetMapping("/{id}")
    public R<CaxGeometricCheckVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(caxGeometricCheckService.queryById(id));
    }

    @GetMapping("/queryByConvertId/{id}")
    @SaCheckPermission("cax:convert:queryByConvertId")
    public R<CaxGeometricCheckVo> queryByConvertId(@NotEmpty(message = "转换记录ID不能为空") @PathVariable("id") String convertId) {
        return R.ok(caxGeometricCheckService.queryByConvertId(Long.valueOf(convertId)));
    }

    /**
     * 新增【cax几何校验】
     */
    @SaCheckPermission("cax:geometricCheck:add")
    @Log(title = "【cax几何校验】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CaxGeometricCheckBo bo) {
        return toAjax(caxGeometricCheckService.insertByBo(bo));
    }

    /**
     * 修改【cax几何校验】
     */
    @SaCheckPermission("cax:geometricCheck:edit")
    @Log(title = "【cax几何校验】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CaxGeometricCheckBo bo) {
        return toAjax(caxGeometricCheckService.updateByBo(bo));
    }

    /**
     * 删除【cax几何校验】
     *
     * @param ids 主键串
     */
    @SaCheckPermission("cax:geometricCheck:remove")
    @Log(title = "【cax几何校验】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(caxGeometricCheckService.deleteWithValidByIds(List.of(ids), true));
    }
}
